/*
 * Copyright (c) 2021.版权所有高金磊
 */

package 领扣算法.AA中等题.最大单词长度乘积;

import 领扣算法.AA中等题.三数之和.Mian;

import java.security.Principal;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedList;

public class Main {

    public int maxProduct(String[] words) {
        LinkedList<HashSet> data=new LinkedList<>();
        for (String word : words) {
            HashSet<Character> characters=new HashSet<>();
            for (char c : word.toCharArray()) {
                characters.add(c);
            }
            data.addLast(characters);
        }
//        Collections.sort(data, new Comparator<HashSet>() {
//            @Override
//            public int compare(HashSet o1, HashSet o2) {
//                return o2.size()-o1.size();
//            }
//        });
        int res=0;
        int pre=0,last;
        while (!data.isEmpty())
        {
            HashSet<Character> characters=data.pollFirst();
            last=pre+1;
            for (HashSet datum : data) {

                HashSet<Character> middle=new HashSet<>(characters);
                middle.retainAll(datum);
                if (middle.isEmpty()){
                   res= Math.max(res,words[pre].length()*words[last].length());
                }
                last++;
            }
            pre++;
        }

        return res;
    }


    public static void main(String arg[]){//main--来自高金磊

        new Main().maxProduct(new String[]{"abcw","baz","foo","bar","xtfn","abcdef"});
    }
}
